'use strict';
module.exports = function (sequelize, DataTypes) {

  var Blacklist = sequelize.define('Blacklist', {
    id: {
      type: DataTypes.INTEGER.UNSIGNED,
      primaryKey: true,
      autoIncrement: true
    },
    userId: {
      type: DataTypes.INTEGER.UNSIGNED,
      allowNull: false
    },
    friendId: {
      type: DataTypes.INTEGER.UNSIGNED,
      allowNull: false
    },
    status: {
      type: DataTypes.BOOLEAN,
      allowNull: false,
      comment: 'true: 拉黑'
    },
    timestamp: {
      type: DataTypes.BIGINT.UNSIGNED,
      allowNull: false,
      defaultValue: 0,
      comment: '时间戳（版本号）'
    }
  }, {
    classMethods: {
      associate: function (models) {
        Blacklist.belongsTo(models.User, {
          foreignKey: 'friendId',
          constraints: false
        });
      }
    },
    indexes: [
      {
        unique: true,
        fields: ['userId', 'friendId']
      }, {
        method: 'BTREE',
        fields: ['userId', 'timestamp']
      }
    ],
    tableName: 'blacklists'
  });

  return Blacklist;
};
